package com.liuxu.topnews.utils;

import java.util.ArrayList;
import java.util.Iterator;

import android.graphics.Rect;

import com.liuxu.topnews.bean.Point;

import static com.liuxu.topnews.MyApplication.height;
import static com.liuxu.topnews.MyApplication.width;


public class MoveUtils {

    public static String clcikHome() {
        return "input keyevent 3";
    }

    public static String clickMenu() {
        return "input keyevent 82";
    }

    public static String getMoveString(Rect rect1, Rect rect2, int speed) {
        Point startpoint = RandomUntil.getPoint(rect1);
        Point endpoint = RandomUntil.getPoint(rect2);
        return "input swipe " + startpoint.x + " " + startpoint.y + " " + endpoint.x + " " + endpoint.y + " " + speed;
    }

    public static String getMoveString(Rect var0, Rect var1, int speed1, int speed2) {
        Point startpoint = RandomUntil.getPoint(var0);
        Point endpoint = RandomUntil.getPoint(var1);
        speed1 = RandomUntil.getNum(speed1, speed2);
        return "input swipe " + startpoint.x + " " + startpoint.y + " " + endpoint.x + " " + endpoint.y + " " + speed1;
    }

    private static ArrayList<String> getMoveSuper(ArrayList<Point> PointInfos) {
        ArrayList points = new ArrayList();
        points.add("sendevent /dev/input/event2 3 57 201");
        Iterator temp = PointInfos.iterator();

        while(temp.hasNext()) {
            Point point = (Point)temp.next();
            points.add("sendevent /dev/input/event2 3 53 " + point.x);
            points.add("sendevent /dev/input/event2 3 54 " + point.y);
            points.add("sendevent /dev/input/event2 0 0 0");
        }

        points.add("sendevent /dev/input/event2 3 57 4294967295");
        points.add("sendevent /dev/input/event2 0 0 0");
        return points;
    }

    public static String moveKeyDwon() {
        return "input keyevent 93";
    }

    public static String moveKeyUp() {
        return "input keyevent 92";
    }

    public static String moveWebScrollDwon() {
        int[] point1 = new int[]{200/width, 400/height};
        int[] point2 = new int[]{800/width, 1000/height};
        int[] point3 = new int[]{200/width, 400/height};
        int[] point4 = new int[]{400/width, 600/height};
        int[] point5 = new int[]{500/width, 800/height};
        return getMoveString(new Rect(point1[0], point2[0], point1[1], point2[1]), new Rect(point3[0], point4[0], point3[1], point4[1]), point5[0], point5[1]);
    }

    public static String moveWebScrollUp() {
        int[] point1 = new int[]{300/width, 350/height};
        int[] point2 = new int[]{400/width, 450/height};
        int[] point3 = new int[]{300/width, 350/height};
        int[] point4 = new int[]{800/width, 850/height};
        int[] point5 = new int[]{800/width, 1000/height};
        return getMoveString(new Rect(point1[0], point2[0], point1[1], point2[1]), new Rect(point3[0], point4[0], point3[1], point4[1]), point5[0], point5[1]);
    }

    public static ArrayList<String> moveWebSuperUp() {
        ArrayList points = new ArrayList();
        points.add(new Point(400/width, 800/height));
        points.add(new Point(400/width, 780/height));
        points.add(new Point(400/width, 760/height));
        points.add(new Point(400/width, 740/height));
        points.add(new Point(400/width, 720/height));
        points.add(new Point(400/width, 700/height));
        return getMoveSuper(points);
    }

    public static ArrayList<String> moveWebSuperUpFast() {
        ArrayList points = new ArrayList();
        points.add(new Point(400/width, 900/height));
        points.add(new Point(400/width, 600/height));
        points.add(new Point(400/width, 400/height));
        return getMoveSuper(points);
    }

    public static ArrayList<String> moveWebSuperDown() {
        ArrayList points = new ArrayList();
        points.add(new Point(400/width, 600/height));
        points.add(new Point(400/width, 620/height));
        points.add(new Point(400/width, 640/height));
        points.add(new Point(400/width, 660/height));
        points.add(new Point(400/width, 680/height));
        points.add(new Point(400/width, 700/height));
        return getMoveSuper(points);
    }
}